<!DOCTYPE html>
<html>
<head lang="en">
	<meta charset="UTF-8">
		<title>试题管理</title>
	<link href="../resources/bootstrap/css/bootstrap.css" rel="stylesheet">
	<link href="../resources/font-awesome/css/font-awesome.min.css" rel="stylesheet">
	<link href="../resources/css/style.css" rel="stylesheet">
	<link href="../resources/css/exam.css" rel="stylesheet">

	<script type="text/javascript" src="../resources/js/jquery/jquery-3.1.1.min.js"></script>
	<script type="text/javascript" src="../resources/vue/vue.js"></script>
	<script type="text/javascript" src="../resources/vue/date.js"></script>
	<script type="text/javascript" src="../resources/bootstrap/js/bootstrap.min.js"></script>
	<script type="text/javascript" src="../resources/js/all.js"></script>
	<script type="text/javascript" src="../resources/js/tag-list.js"></script>
	<script type="text/javascript" src="../resources/js/add-tag.js"></script>
	<script type="text/javascript" src="../resources/js/jquery.validation/1.14.0/jquery.validate.min.js"></script>
	<script type="text/javascript" src="../resources/laypage/laypage.js" charset="utf-8"></script>
	<script type="text/javascript" src="../resources/layui/layui.all.js" charset="utf-8"></script>
	<script type="text/javascript" src="../resources/bootstrap/js/bootstrapValidator.min.js"></script>
	<link href="../resources/bootstrap/css/bootstrapValidator.min.css" rel="stylesheet">
	</head>
	<body>
	<div class="container" style="min-height:500px;">

		<div class="row">
			<div class="col-md-12">
				<div class="lrform">
							<h1><i class="glyphicon glyphicon-random"></i> 添加知识分类 </h1>
						</div>
						<div class="page-content">

							<form id="point-add-form" style="margin-top:40px; padding-left: 100px;">
								<div class="form-line form-field" style="display: block;">
									<span class="form-label"><span class="warning-label"></span>题库：</span>
									<select id="field-input-select" class="df-input-narrow">


									</select>
									<br>
								</div>
								<div class="form-group">
									<span class="form-label"><span class="warning-label"></span>知识分类名：</span>
										<input type="text" class="form-control" id="pointName" name="pointName"><span class="form-message"></span>
									<br>
								</div>
								<div class="form-group">
									<span class="form-label"><span class="warning-label"></span>知识分类描述：</span>
										<input type="text" class="form-control" id="memo"name="memo"><span class="form-message"></span>
									<br>
								</div>


								<div class="form-group">
 									<button type="button" id="btn-save" class="df-submit btn btn-info">提交</button>
									<button type="button" id="btn-cancle" class="df-submit btn btn-info">取消</button>
								</div>
							</form>
							

						</div>
					</div>
				</div>
			</div>
		</div>

	</body>
</html>

<script>

    $.ajax({
        type:'post',
        dataType : 'json',
        url : '/getListField',
        success : function(data) {
            $(".fields").remove();
            $.each(data,function (index,obj) {
                var v  = "<option class='fields' value='"+obj.fieldId+"'>"+obj.fieldName+"</option>";
                $("#field-input-select").append(v);
            })
        },error:function () {
        //    alert("失败")
        }
    });


    var  addKP = function () {

        $.ajax({
            type:'post',
            dataType : 'json',
            url : '/addKnowledgePoint',
            data :
             /*   $("#point-add-form").serialize(),*/

				{
                     fid:$("#field-input-select").val(),
				    pointName:$("#pointName").val(),
					memo:$("#memo").val()
				},
            success : function(data) {
                if(data > 0){
                    var index = parent.layer.getFrameIndex(window.name);
                    parent.getKnowledgePageList();
                    parent.layer.close(index);
                    getKnowledgePageList();
                }
            },error:function () {
            //    alert("失败")
            }
        });
    };

    $("#btn-save").click(function () {
        $("#point-add-form").bootstrapValidator('validate');//提交验证
        if ($("#point-add-form").data('bootstrapValidator').isValid()) {//获取验证结果，如果成功，执行下面代码
           addKP();
        }
    });


    $('#point-add-form').bootstrapValidator({
        live: 'enabled',//验证时机，enabled是内容有变化就验证（默认），disabled和submitted是提交再验证
        excluded: [':disabled', ':hidden', ':not(:visible)'],//排除无需验证的控件，比如被禁用的或者被隐藏的
        submitButtons: '#btn-save',//指定提交按钮，如果验证失败则变成disabled
        feedbackIcons: {
            valid: 'glyphicon glyphicon-ok',
            invalid: 'glyphicon glyphicon-remove',
            validating: 'glyphicon glyphicon-refresh'
        },
        fields: {
            pointName: {
                validators: {
                    notEmpty: {//检测非空,radio也可用
                        message: '必须输入知识点名'
                    },
                    stringLength: {//检测长度
                        min:2,
                        max: 20,
                        message: '长度必须在2-20之间'
                    },

                }
            },
            memo: {
                validators: {
                    notEmpty: {//检测非空,radio也可用
                        message: '必须输入描述'
                    },
                    stringLength: {//检测长度

                        max: 50,
                        message: '长度必须在小于50'
                    }

                }
            }
        }
    });


    $("#btn-cancle").click(function() {
        var index = parent.layer.getFrameIndex(window.name);
        parent.getKnowledgePageList();
        parent.layer.close(index);

    });

</script>